package com.cuit.freshmanMS.controller;

import com.cuit.freshmanMS.domain.Class_;
import com.cuit.freshmanMS.query.ClassQuery;
import com.cuit.freshmanMS.service.ClassService;
import com.cuit.freshmanMS.util.result.CommonResult;
import com.cuit.freshmanMS.util.result.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
public class ClassController {
    @Autowired
    private ClassService classService;

    @GetMapping("/class")
    public List<Class_> loadAll(){
        List<Class_> classS = classService.loadAll();
        return classS;
    }

    @PostMapping("/class")
    public CommonResult addClass(@RequestBody Class_ class_){
        return classService.addClass(class_);
    }

    @PutMapping("/class")
    public CommonResult updateClass(@RequestBody Class_ class_){
        return classService.updateClass(class_);
    }

    @DeleteMapping("/class/{cno}")
    public CommonResult deleteClass(@PathVariable("cno") Integer cno){

        return classService.deleteAcaByCno(cno);

    }

    @DeleteMapping("/class/batchDelete")
    public CommonResult batchDelete(@RequestBody List<Integer> cnos){
        return classService.batchDelete(cnos);
    }

    @PostMapping("/class/selectAll")
    PageResult<Class_> selectAll(@RequestBody ClassQuery classQuery) {
        return classService.selectAll(classQuery);
    }
}
